package blue.mqtt4j.core.handler;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.handler.codec.mqtt.MqttMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Jin Zheng
 * @since 1.0 2020-09-29
 */
public class SenderListener implements ChannelFutureListener
{
	private static Logger logger = LoggerFactory.getLogger(SenderListener.class);

	private final MqttMessage message;

	public SenderListener(MqttMessage message)
	{
		this.message = message;
	}

	@Override
	public void operationComplete(ChannelFuture future) throws Exception
	{
		if (future.isSuccess())
		{
			if (logger.isDebugEnabled())
			{
				logger.debug("Send successful: {}", message.fixedHeader());
			}
		}
		else
		{
			logger.error("Send failure");
		}
	}
}
